﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using TyMES.Model.Record;


namespace TyMES.ViewModel.Record.StockInRecordVMs
{
    public partial class StockInRecordListVM : BasePagedListVM<StockInRecord_View, StockInRecordSearcher>
    {

        protected override IEnumerable<IGridColumn<StockInRecord_View>> InitGridHeader()
        {
            return new List<GridColumn<StockInRecord_View>>{
                this.MakeGridHeader(x => x.factoryCode),
                this.MakeGridHeader(x => x.hjCode),
                this.MakeGridHeader(x => x.zcCode),
                this.MakeGridHeader(x => x.sort),
                this.MakeGridHeader(x => x.batchCode),
                this.MakeGridHeader(x => x.BindTime),
                this.MakeGridHeader(x => x.ProductType),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<StockInRecord_View> GetSearchQuery()
        {
            var query = DC.Set<StockInRecord>()
                .CheckContain(Searcher.factoryCode, x=>x.factoryCode)
                .CheckContain(Searcher.hjCode, x=>x.hjCode)
                .CheckContain(Searcher.zcCode, x=>x.zcCode)
                .CheckContain(Searcher.sort, x=>x.sort)
                .CheckContain(Searcher.batchCode, x=>x.batchCode)
                .CheckBetween(Searcher.BindTime?.GetStartTime(), Searcher.BindTime?.GetEndTime(), x => x.BindTime, includeMax: false)
                .Select(x => new StockInRecord_View
                {
				    ID = x.ID,
                    factoryCode = x.factoryCode,
                    hjCode = x.hjCode,
                    zcCode = x.zcCode,
                    sort = x.sort,
                    batchCode = x.batchCode,
                    BindTime = x.BindTime,
                    ProductType = x.ProductType,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class StockInRecord_View : StockInRecord{

    }
}
